package com.stek.main;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.stek.R;
import com.stek.base.BaseOverLayActivity;
import com.stek.floaticon.FloatActivity;
import com.stek.panel.PanelActivity;
import com.stek.settings.SettingsActivity;
import com.stek.utils.AdMode;
import com.stek.utils.AppUtils;
import com.stek.utils.Logging;

public class MainActivity extends BaseOverLayActivity implements
		OnItemClickListener {

	private ListView mListView;
	private Object mSyncObject = new Object();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mListView = (ListView) findViewById(R.id.list);
		mListView.setOnItemClickListener(this);
		loadData();
		startService(new Intent(getApplicationContext(), MainService.class));
		adView = (AdView) findViewById(R.id.admod);
		AdMode.init(adView);
	}

	private void loadData() {
		ArrayList<MainInfo> objects = new ArrayList<MainInfo>();
		objects.add(new MainInfo(getString(R.string.settings),
				R.drawable.ic_settings_general, SettingsActivity.class));
		objects.add(new MainInfo(getString(R.string.panel_settings),
				R.drawable.ic_panel, PanelActivity.class));
		objects.add(new MainInfo(getString(R.string.change_float_icon),
				R.drawable.ic_changeicon, FloatActivity.class));
		MainBaseAdapter adapter = new MainBaseAdapter(objects,
				getApplicationContext());
		mListView.setAdapter(adapter);

	}

	@Override
	protected void initActionBar() {
		super.initActionBar();
		getSupportActionBar().setDisplayShowTitleEnabled(false);
		getSupportActionBar().setDisplayUseLogoEnabled(false);
		getSupportActionBar().setDisplayHomeAsUpEnabled(false);
		getSupportActionBar().setDisplayShowHomeEnabled(false);
		getSupportActionBar()
				.setBackgroundDrawable(
						new ColorDrawable(getResources().getColor(
								R.color.transparent)));
	}

	public void onSettings(View view) {
		AppUtils.launchActivity(getApplicationContext(), SettingsActivity.class);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		synchronized (mSyncObject) {
			MainInfo mainInfo = (MainInfo) parent.getAdapter()
					.getItem(position);
			Class<?> clazz = mainInfo.clazz;
			if (null != clazz) {
				AppUtils.launchActivity(MainActivity.this, clazz, false);
			}
		}

	}
}
